package com.boss.core.manage;

import hudson.DescriptorExtensionList;
import hudson.ExtensionPoint;
import hudson.model.Describable;
import hudson.model.Descriptor.FormException;
import hudson.model.Hudson;

import net.sf.json.JSONObject;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

/**
 * Boss Property - acts as superclass
 * @author Momin Noor Khan
 */
public abstract class BossProperty implements Describable<BossProperty>, ExtensionPoint {
    private String name;
    private String value;
    private String description;

    //no-args constructor
    public BossProperty() {
        this(null, null, null);
    }

    @DataBoundConstructor
    public BossProperty(String name, String value, String description) {
        // super(name, description);
        this.name = name;
        this.value = value;
        this.description = description;
    }

    public BossProperty(String name, String value) {
        this(name, value, null);
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public BossPropertyDescriptor getDescriptor() {
        return (BossPropertyDescriptor) Hudson.getInstance().getDescriptorOrDie(getClass());
    }

    public static DescriptorExtensionList<BossProperty, BossPropertyDescriptor> all() {
        return Hudson.getInstance().<BossProperty, BossPropertyDescriptor>getDescriptorList(BossProperty.class);
    }

    public BossProperty reconfigure(StaplerRequest req, JSONObject form) throws FormException {
        return getDescriptor().newInstance(req, form);
    }
}
